import api from "../../api";
import {settings} from "../../assets/settings";
const app = {
    state: {
        lang: '',
        isFullScreen: false,
        menuTheme: 'dark', // 主题
        theme: {},
      // 面包屑数组
        menuList: [],
      gameList:[],
        channelList:[]
    },
    mutations: {
        setChannelList (state, list) {
        state.channelList = list;
      },
      setGameList (state, list) {
        state.gameList = list;
        sessionStorage.setItem("gameList",JSON.stringify(list));
      },
      setTheme (state, theme) {
        state.theme = theme;
        localStorage.setItem("myTheme",JSON.stringify(theme));
      }
    },
  getters:{

  },
  actions:{
    getChannelListData(context,set){
      api.getChannelList(set)
        .then((response) =>{
          context.commit('setChannelList',response.data);
        })
        .catch((error)=> {
          console.log(error);
        });
    },
    getThemeData(context){
      let themes = JSON.parse(localStorage.getItem("myTheme"))||settings.themeSetting;
      context.commit('setTheme',themes);
    },
    getGameListData(context,para){
      api.getGameList(para)
        .then((response) =>{
          if(Array.isArray(response.data)){
            context.commit('setGameList',response.data);
          }
        })
        .catch((error)=> {
          console.log(error);
        });
    }
  }
};

export default app;
